b6cc2b76fae18930da6a4598e67548bccf5a1e48
5 hovzer
= $.getFootHovzer();
10 * Enabled server-side through `$wgDebugToolbar`.
14 * @author John Du Hart
19 * Toolbar container element
26 * Object containing data for the debug toolbar
33 * Initialize the debugging pane
35 * Shouldn't be called before the document is ready
36 * (since it binds to elements on the page).
38 * @param {Object} [data] Defaults to 'debugInfo' from mw.config
40 init: function ( data
) {
42 this.data
= data
|| mw
.config
.get( 'debugInfo' );
45 // Insert the container into the DOM
46 hovzer
.$.append( this.$container
);
49 $( '.mw-debug-panelink' ).click( this.switchPane
);
53 * Switch between panes
55 * Should be called with an HTMLElement as its thisArg,
56 * because it's meant to be an event handler.
58 * TODO: Store cookie for last pane open.
60 * @param {jQuery.Event} e
62 switchPane: function ( e
) {
63 var currentPaneId
= debug
.$container
.data( 'currentPane' ),
64 requestedPaneId
= $( this ).prop( 'id' ).substr( 9 ),
65 $currentPane
= $( '#mw-debug-pane-' + currentPaneId
),
66 $requestedPane
= $( '#mw-debug-pane-' + requestedPaneId
),
69 function updateHov() {
76 // Skip hash fragment handling. Prevents screen from jumping.
79 $( this ).addClass( 'current ' );
80 $( '.mw-debug-panelink' ).not( this ).removeClass( 'current ' );
82 // Hide the current pane
83 if ( requestedPaneId
=== currentPaneId
) {
84 $currentPane
.slideUp( updateHov
);
85 debug
.$container
.data( 'currentPane', null );
89 debug
.$container
.data( 'currentPane', requestedPaneId
);
91 if ( currentPaneId
=== undefined || currentPaneId
=== null ) {
92 $requestedPane
.slideDown( updateHov
);
95 $requestedPane
.show();
101 * Construct the HTML for the debugging toolbar
103 buildHtml: function () {
104 var $container
, $bits
, panes
, id
, gitInfo
;
106 $container
= $( '<div id="mw-debug-toolbar" class="mw-debug" lang="en" dir="ltr"></div>' );
108 $bits
= $( '<div class="mw-debug-bits"></div>' );
111 * Returns a jQuery element for a debug-bit div
117 function bitDiv( id
) {
118 return $( '<div>' ).prop( {
119 id
: 'mw-debug-' + id
,
120 className
: 'mw-debug-bit'
126 * Returns a jQuery element for a pane link
130 * @param {string} text
133 function paneLabel( id
, text
) {
136 className
: 'mw-debug-panelabel',
137 href
: '#mw-debug-pane-' + id
143 * Returns a jQuery element for a debug-bit div with a for a pane link
146 * @param {string} id CSS id snippet. Will be prefixed with 'mw-debug-'
147 * @param {string} text Text to show
148 * @param {string} count Optional count to show
151 function paneTriggerBitDiv( id
, text
, count
) {
153 text
= text
+ ' (' + count
+ ')';
155 return $( '<div>' ).prop( {
156 id
: 'mw-debug-' + id
,
157 className
: 'mw-debug-bit mw-debug-panelink'
159 .append( paneLabel( id
, text
) )
163 paneTriggerBitDiv( 'console', 'Console', this.data
.log
.length
);
165 paneTriggerBitDiv( 'querylist', 'Queries', this.data
.queries
.length
);
167 paneTriggerBitDiv( 'debuglog', 'Debug log', this.data
.debugLog
.length
);
169 paneTriggerBitDiv( 'request', 'Request' );
171 paneTriggerBitDiv( 'includes', 'PHP includes', this.data
.includes
.length
);
174 if ( this.data
.gitRevision
!== false ) {
175 gitInfo
= '(' + this.data
.gitRevision
.substring( 0, 7 ) + ')';
176 if ( this.data
.gitViewUrl
!== false ) {
178 .attr( 'href', this.data
.gitViewUrl
)
183 bitDiv( 'mwversion' )
184 .append( $( '<a href="//www.mediawiki.org/">MediaWiki</a>' ) )
185 .append( document
.createTextNode( ': ' + this.data
.mwVersion
+ ' ' ) )
188 if ( this.data
.gitBranch
!== false ) {
189 bitDiv( 'gitbranch' ).text( 'Git branch: ' + this.data
.gitBranch
);
192 bitDiv( 'phpversion' )
193 .append( $( '<a href="//www.php.net/"></a>' ).text( 'PHP' ) )
194 .append( ': ' + this.data
.phpVersion
);
197 .text( 'Time: ' + this.data
.time
.toFixed( 5 ) );
200 .text( 'Memory: ' + this.data
.memory
+ ' (Peak: ' + this.data
.memoryPeak
+ ')' );
202 $bits
.appendTo( $container
);
205 console
: this.buildConsoleTable(),
206 querylist
: this.buildQueryTable(),
207 debuglog
: this.buildDebugLogTable(),
208 request
: this.buildRequestPane(),
209 includes
: this.buildIncludesPane()
212 for ( id
in panes
) {
213 if ( !panes
.hasOwnProperty( id
) ) {
219 className
: 'mw-debug-pane',
220 id
: 'mw-debug-pane-' + id
223 .appendTo( $container
);
226 this.$container
= $container
;
230 * Build the console panel
232 buildConsoleTable: function () {
233 var $table
, entryTypeText
, i
, length
, entry
;
235 $table
= $( '<table id="mw-debug-console">' );
237 $( '<colgroup>' ).css( 'width', /* padding = */ 20 + ( 10 * /* fontSize = */ 11 ) ).appendTo( $table
);
238 $( '<colgroup>' ).appendTo( $table
);
239 $( '<colgroup>' ).css( 'width', 350 ).appendTo( $table
);
242 entryTypeText = function ( entryType
) {
243 switch ( entryType
) {
255 for ( i
= 0, length
= this.data
.log
.length
; i
< length
; i
+= 1 ) {
256 entry
= this.data
.log
[i
];
257 entry
.typeText
= entryTypeText( entry
.type
);
261 .text( entry
.typeText
)
262 .addClass( 'mw-debug-console-' + entry
.type
)
264 .append( $( '<td>' ).html( entry
.msg
) )
265 .append( $( '<td>' ).text( entry
.caller
) )
273 * Build query list pane
277 buildQueryTable: function () {
278 var $table
, i
, length
, query
;
280 $table
= $( '<table id="mw-debug-querylist"></table>' );
283 .append( $( '<th>#</th>' ).css( 'width', '4em' ) )
284 .append( $( '<th>SQL</th>' ) )
285 .append( $( '<th>Time</th>' ).css( 'width', '8em' ) )
286 .append( $( '<th>Call</th>' ).css( 'width', '18em' ) )
289 for ( i
= 0, length
= this.data
.queries
.length
; i
< length
; i
+= 1 ) {
290 query
= this.data
.queries
[i
];
293 .append( $( '<td>' ).text( i
+ 1 ) )
294 .append( $( '<td>' ).text( query
.sql
) )
295 .append( $( '<td class="stats">' ).text( ( query
.time
* 1000 ).toFixed( 4 ) + 'ms' ) )
296 .append( $( '<td>' ).text( query
['function'] ) )
305 * Build legacy debug log pane
309 buildDebugLogTable: function () {
310 var $list
, i
, length
, line
;
313 for ( i
= 0, length
= this.data
.debugLog
.length
; i
< length
; i
+= 1 ) {
314 line
= this.data
.debugLog
[i
];
316 .html( mw
.html
.escape( line
).replace( /\n/g, '<br />\n' ) )
324 * Build request information pane
328 buildRequestPane: function () {
330 function buildTable( title
, data
) {
331 var $unit
, $table
, key
;
333 $unit
= $( '<div>' ).append( $( '<h2>' ).text( title
) );
335 $table
= $( '<table>' ).appendTo( $unit
);
338 .html( '<th>Key</th><th>Value</th>' )
341 for ( key
in data
) {
342 if ( !data
.hasOwnProperty( key
) ) {
347 .append( $( '<th>' ).text( key
) )
348 .append( $( '<td>' ).text( data
[key
] ) )
356 .text( this.data
.request
.method
+ ' ' + this.data
.request
.url
)
357 .append( buildTable( 'Headers', this.data
.request
.headers
) )
358 .append( buildTable( 'Parameters', this.data
.request
.params
) );
362 * Build included files pane
366 buildIncludesPane: function () {
367 var $table
, i
, length
, file
;
369 $table
= $( '<table>' );
371 for ( i
= 0, length
= this.data
.includes
.length
; i
< length
; i
+= 1 ) {
372 file
= this.data
.includes
[i
];
374 .append( $( '<td>' ).text( file
.name
) )
375 .append( $( '<td class="nr">' ).text( file
.size
) )
383 }( mediaWiki
, jQuery
) );